<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AJAX_post</title>
    
</head>
<body>
    <input type="text">
    <span></span>
    <script>
        let input=document.querySelector("input");
        let span=document.querySelector("span");
        input.onchange=()=>{
            let xhr=new XMLHttpRequest();
            xhr.open('post',"https://mock.mengxuegu.com/mock/6673cc1fbe17764121dfc577/ajax/phone");//配置请求
            xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xhr.send("phone="+input.value);//异步发送请求
            xhr.responseType="json"
            xhr.onload=()=>{//异步接收结果
                console.log(xhr.response);
                if (xhr.response.data.code===10001){
                    span.innerText="手机号已注册，无法使用";
                }else{
                    span.innerText="手机号未注册，可以使用";
                }
            }
        }
    </script>
</body>
</html>